﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using Medianamik.UI.Controls;
using NUnit.Framework;

namespace Medianamik.Tests.Unit.Medianamik.UI
{
    [TestFixture]
    public class MedianamikControlLabelTest
    {
        [Test]
        public void Should_render_icon_depending_on_IsLanguageNeutral_value()
        {
            string languageNeutralIconPath = "/Medianamik/images/Icones/Ico_ProprieteNeutreLangue.png";

            var labelWithIcon = new MedianamikControlLabel {IsLanguageNeutral = true};

            Assert.That(RenderControl(labelWithIcon), Is.StringContaining(languageNeutralIconPath));

            var labelWithoutIcon = new MedianamikControlLabel { IsLanguageNeutral = false };

            Assert.That(RenderControl(labelWithoutIcon), Is.Not.StringContaining(languageNeutralIconPath));
        }

        [Test]
        public void Should_render_icon_depending_on_IsRequired_value()
        {
            string requiredFieldIconPath = "/Medianamik/images/Icones/Ico_ProprieteObligatoire.png";

            var labelWithIcon = new MedianamikControlLabel { IsRequired = true };
            
            Assert.That(RenderControl(labelWithIcon), Is.StringContaining(requiredFieldIconPath));

            var labelWithoutIcon = new MedianamikControlLabel { IsRequired = false };

            Assert.That(RenderControl(labelWithoutIcon), Is.Not.StringContaining(requiredFieldIconPath));

        }

        private string RenderControl(Control control)
        {
            var builder = new StringBuilder();
            var textWriter = new StringWriter(builder);
            var htmlWriter = new HtmlTextWriter(textWriter);
            control.RenderControl(htmlWriter);
            return builder.ToString();
        }
    }
}